package com.global.college.ui.activity;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.global.college.R;
import com.global.college.base.BaseActivity;
import com.global.college.base.baselist.HsScrollViewPagerAdapter;
import com.global.college.ui.fragment.order.OrderCommonFragment;
import com.global.college.widget.tab.SlidingTabLayout;
import com.global.college.widget.tab.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 订单中心
 */
public class OrderCenterActivity extends BaseActivity {
    @BindView(R.id.mSlidingTab)
    SlidingTabLayout mSlidingTab;
    @BindView(R.id.viewPager)
    ViewPager viewPager;
    private List<Fragment> mFragments = new ArrayList<>();
    private List<String> mTitles = new ArrayList<>();
    private int currentPosition = 2;
    @Override
    public int getContentViewId() {
        return R.layout.activity_order_center;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        useImmersionBar = false;
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onCreateNew(Bundle savedInstanceState) {
        setShowTitleBar(false);
        initTab();
        setListener();
    }
    private void setListener() {
        mSlidingTab.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewPager.setCurrentItem(position);
                currentPosition = position;
            }

            @Override
            public void onTabReselect(int position) {
            }
        });
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }

            @Override
            public void onPageSelected(int position) {
                currentPosition = position;
            }

            @Override
            public void onPageScrollStateChanged(int state) {
            }
        });
    }

    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    private void initTab() {
        List<String> strs = new ArrayList<>();
        mTitles.add(getString(R.string.order_all));
        mTitles.add(getString(R.string.order_unpay));
        mTitles.add(getString(R.string.order_studyed));
        mTitles.add(getString(R.string.order_cancle));
        for (int i = 0; i < mTitles.size(); i++) {
            strs.add(mTitles.get(i));
            switch (mTitles.get(i)) {
                default:
                    mFragments.add(OrderCommonFragment.newInstance(String.valueOf(i)));
                    break;
            }
        }
        HsScrollViewPagerAdapter adapter = new HsScrollViewPagerAdapter(getSupportFragmentManager(), mFragments, strs);
        if (mFragments.size() < 1) {
            return;
        }
        viewPager.setAdapter(adapter);
        mSlidingTab.setViewPager(viewPager);
        viewPager.setCurrentItem(currentPosition);
    }
    @Override
    public void getInitData() {
    }

}